<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui, viewport-fit=cover">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>My App</title>
    <link rel="stylesheet" href="../../packages/core/css/framework7.min.css">
  </head>
  <body>
    <div id="app">
      <div class="view view-main view-init">
        <div class="page" data-page="home">
          <div class="navbar">
            <div class="navbar-inner">
              <div class="left"></div>
              <div class="title sliding">Infinite Scroll</div>
              <div class="right"></div>
            </div>
          </div>
          <div class="page-content infinite-scroll-content">
            <div class="list simple-list">
              <ul>
                <li>Item 1</li>
                <li>Item 2</li>
                <li>Item 3</li>
                <li>Item 4</li>
                <li>Item 5</li>
                <li>Item 6</li>
                <li>Item 7</li>
                <li>Item 8</li>
                <li>Item 9</li>
                <li>Item 10</li>
                <li>Item 11</li>
                <li>Item 12</li>
                <li>Item 13</li>
                <li>Item 14</li>
                <li>Item 15</li>
                <li>Item 16</li>
                <li>Item 17</li>
                <li>Item 18</li>
                <li>Item 19</li>
                <li>Item 20</li>
              </ul>
            </div>
            <div class="preloader infinite-scroll-preloader"></div>
          </div>
        </div>
      </div>
    </div>
    <script type="text/javascript" src="../../packages/core/js/framework7.min.js"></script>
    <script>
      var theme = 'ios';
      if (location.href.indexOf('theme=md') >= 0) theme = 'md';
      var plugin = {
        params: {
          theme: theme,
          root: '#app',
        }
      };
      if (Framework7.use) Framework7.use(plugin);
      else if (Framework7.Class && Framework7.Class.use) Framework7.Class.use(plugin);
      
    </script>
    <script>
      var app = new Framework7();
      
      var $$ = Dom7;
      
      // Loading flag
      var allowInfinite = true;
      
      // Last loaded index
      var lastItemIndex = $$('.list li').length;
      
      // Max items to load
      var maxItems = 200;
      
      // Append items per load
      var itemsPerLoad = 20;
      
      // Attach 'infinite' event handler
      $$('.infinite-scroll-content').on('infinite', function () {
        // Exit, if loading in progress
        if (!allowInfinite) return;
      
        // Set loading flag
        allowInfinite = false;
      
        // Emulate 1s loading
        setTimeout(function () {
          // Reset loading flag
          allowInfinite = true;
      
          if (lastItemIndex >= maxItems) {
            // Nothing more to load, detach infinite scroll events to prevent unnecessary loadings
            app.infiniteScroll.destroy('.infinite-scroll-content');
            // Remove preloader
            $$('.infinite-scroll-preloader').remove();
            return;
          }
      
          // Generate new items HTML
          var html = '';
          for (var i = lastItemIndex + 1; i <= lastItemIndex + itemsPerLoad; i++) {
            html += '<li>Item ' + i + '</li>';
          }
      
          // Append new items
          $$('.list ul').append(html);
      
          // Update last loaded index
          lastItemIndex = $$('.list li').length;
        }, 1000);
      });
    </script>
  </body>
</html>